package com.r2coding.music.controller;

import java.util.Date;

import com.r2coding.common.enums.Module;
import com.r2coding.common.enums.OperationType;
import com.r2coding.music.annotation.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.r2coding.music.entity.SongListCategoryEntity;
import com.r2coding.music.service.SongListCategoryService;
import com.r2coding.common.util.Result;

/**
 * 歌单分类
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-05-14 16:21:09
 */
@RestController
@RequestMapping("/songlistcategory")
public class SongListCategoryController {
    @Autowired
    private SongListCategoryService songListCategoryService;

    /**
     * 保存
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.INSERT, description = "保存歌单分类")
    @PreAuthorize("hasAuthority('songCategory:add')")
    @PostMapping("/save")
    public Result save(@RequestBody SongListCategoryEntity songListCategory){
        songListCategory.setDeleted(0);
        songListCategory.setUpdateTime(new Date());
        songListCategory.setCreateTime(new Date());
		songListCategoryService.save(songListCategory);
        return Result.ok();
    }

    /**
     * 修改
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.UPDATE, description = "修改歌单分类")
    @PreAuthorize("hasAuthority('songCategory:edit')")
    @PutMapping("/update")
    public Result update(@RequestBody SongListCategoryEntity songListCategory){
        songListCategory.setUpdateTime(new Date());
		songListCategoryService.updateById(songListCategory);
        return Result.ok();
    }

    /**
     * 删除
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.DELETE, description = "删除歌单分类")
    @PreAuthorize("hasAuthority('songCategory:delete')")
    @RequestMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
		songListCategoryService.removeById(id);
        return Result.ok();
    }

}
